CSharpTest.Net
Write(Int64,Byte[],Int32,Int32) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > BackgroundWriter Class > Write Method : Write(Int64,Byte[],Int32,Int32) Method

position
buffer
offset
length

Glossary Item Box

Write a series of bytes to the stream at the specified position

Syntax

Visual Basic (Declaration) 
Public Overloads Sub Write( _
   ByVal position As Long, _
   ByVal buffer() As Byte, _
   ByVal offset As Integer, _
   ByVal length As Integer _
) 
C# 
public void Write( 
   long position,
   byte[] buffer,
   int offset,
   int length
)

Parameters

position
buffer
offset
length

Example

Library/Library.Test/TestBackgroundWriter.cs

C#Copy Code
using (TestStream io = new TestStream())
using (BackgroundWriter wtr = new BackgroundWriter(io))
{
    wtr.Write(0L, new byte[100], 0, 100);
    wtr.Perform(s => Thread.Sleep(50));
    wtr.Write(100L, new byte[] { 99 }, 0, 1);
    wtr.Write(100L, new byte[] { 42, 43 }, 0, 2);

    // Read scans the pending writes for writes at the provided offset and returns the last result
    byte[] read = new byte[100];
    Assert.AreEqual(2, wtr.Read(100L, read, 0, 100));
    Assert.AreEqual(42, (int)read[0]);
    Assert.AreEqual(43, (int)read[1]);
}
VB.NETCopy Code
Using io As New TestStream()
    Using wtr As New BackgroundWriter(io)
        wtr.Write(0L, New Byte(100) {}, 0, 100)
        wtr.Perform(Function(s) Thread.Sleep(50))
        wtr.Write(100L, New Byte() {99}, 0, 1)
        wtr.Write(100L, New Byte() {42, 43}, 0, 2)

        ' Read scans the pending writes for writes at the provided offset and returns the last result
        Dim read As Byte() = New Byte(100) {}
        Assert.AreEqual(2, wtr.Read(100L, read, 0, 100))
        Assert.AreEqual(42, DirectCast(read(0), Integer))
        Assert.AreEqual(43, DirectCast(read(1), Integer))
    End Using
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys